# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2015 Jeafea (<1062042200@qq.com>)
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp import models, fields, api, exceptions,_
from openerp.exceptions import except_orm, Warning, RedirectWarning

class CommissionPlan(models.Model):
    _name = 'commission.plan'
    _description = 'commission.plan'

    name = fields.Char('Name', required=True)
    active = fields.Boolean(default=True)
    version_id = fields.One2many('commission.version', 'plan_id')
    type = fields.Selection([
        ('sale','Sale'),
        ('purchase','Purchase'),
    ])


class CommissionVersion(models.Model):
    _name = 'commission.version'
    _description = 'commission.version'

    name = fields.Char('Name', required=True)
    active = fields.Boolean(default=True)
    plan_id = fields.Many2one('commission.plan')
    date_start = fields.Date()
    date_end = fields.Date()
    version_item = fields.One2many('commission.version.item', 'version_id')

class CommissionVersionItem(models.Model):
    _name = 'commission.version.item'
    _description = 'commission.version.item'

    name = fields.Char(u'提成规则', required=True)
    version_id = fields.Many2one('commission.version')
    product_id= fields.Many2one('product.product')
    categ_id = fields.Many2one('product.category')
    sequence = fields.Integer(u'序列')
    base = fields.Selection([
        ('public','Public_price'),
        ('settlement','Settlement_price'),
        ('cost','Cost_price')
    ],required=True,)
    min_quantity = fields.Integer()
    type = fields.Selection(
        selection=[
            ("amount", "Amount"),
            ("percent", "Percentage"),
        ],string="Type", required=True,default='percent')
    amount = fields.Float(string="amount")
    percentage = fields.Float(string="percentage")
